package com.realeyes.plugins.custom
{
	import com.realeyes.plugins.custom.element.CustomSampleElement;
	
	import flash.external.ExternalInterface;
	
	import org.osmf.media.MediaElement;
	import org.osmf.media.MediaFactoryItem;
	import org.osmf.media.MediaFactoryItemType;
	import org.osmf.media.PluginInfo;
	import org.osmf.net.NetLoader;
	
	public class CustomSamplePluginInfo extends PluginInfo
	{
		// Plugin Namespace
		static public const CUSTOM_PLUGIN_NAMESPACE:String = "http://www.realeyes.com/osmf/plugins/custom/sample";
		
		public function CustomSamplePluginInfo()
		{
			//Marker 2: Specify the media items that this plugin will handle 
			var items:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
			
			//Marker 3: Let the MediaFactory know what kinda of media the plugin can handle - for now we'll go with the built in NetLoader.canHandleResource
			var loader:NetLoader = new NetLoader();
			var item:MediaFactoryItem = new MediaFactoryItem( 
				"com.realeyes.plugins.custom.sample", 
				loader.canHandleResource, 
				createMediaElement,
				MediaFactoryItemType.PROXY
			);
			items.push( item );
			
			super( items, elementCreated );
		}
		
		public function createMediaElement():Object
		{
			showMessage( "Create plugin element" );
			
			//Marker 4: Create a new CustomSampleElement
			return new CustomSampleElement();
		}
		
		protected function elementCreated( element:MediaElement ):void 
		{
			showMessage( "Element created!" );
		}
		
		// ==================================================
		// Helper methods
		// ==================================================
		
		protected function showMessage( msg:String ):void 
		{
			ExternalInterface.call( "showMessage", msg );
			trace( msg );
		}
	}
}